package util;

import color.CLRConvert;

public class GeoTriangle
{
	protected float[] normal;
	
	public double Strike; // radians
	public double StrikeDeg;
	public double Dip;
	public double DipDeg;
	public double Roughness;
	public double RoughnessDeg;
	
	public boolean Selected;

	public int[] vertexkeys;
	public int[] triangle_neighbours = null; // TODO: complete this later
	
	public GeoTriangle()
	{
		normal = null;
		vertexkeys = new int[3];
		
		Strike = 0.0;
		StrikeDeg = 0.0;
		
		Dip = 0.0;
		DipDeg = 0.0;
		
		Roughness = 0.0;
		
		Selected = false;
	}
	
	public void setNormal(float[] n)
	{
		normal = new float[3];
		normal[0] = n[0];
		normal[1] = n[1];
		normal[2] = n[2];
	}	
	public float[] getNormal() { return normal; }
	
	public void setStrike(double s)
	{
		Strike = s;
		StrikeDeg = Math.toDegrees(s);
		
		// go round and round until we are in range
//		StrikeDeg = StrikeDeg - 90.0;
		while (StrikeDeg >= 360) StrikeDeg = StrikeDeg - 360.0;
		while (StrikeDeg < 0) StrikeDeg = StrikeDeg + 360.0;
	}
	
	public void setDip(double d)
	{
		Dip = d;
		DipDeg = Math.toDegrees(d);
	}
	
	
	public void setRoughness(double r)
	{
		Roughness = r;
		RoughnessDeg = Math.toDegrees(r);
	}
	
	// assumes that the input keys are actually vertex keys
	public static String CreateTriagnleKey(String k0, String k1, String k2) { return k0+","+k1+","+k2;  }

	// NOTE: following functions are exactly the same as their named counter parts with exception to the parameters
	public static float[] GetStrikeDipColor(GeoTriangle g) { return CLRConvert.GetStrikeDipColor(g.StrikeDeg, g.DipDeg); }
	public static float[] GetStrikeOnlyColor(GeoTriangle g) { return CLRConvert.GetStrikeOnlyColor(g.StrikeDeg); }
	public static float[] GetDipOnlyColor(GeoTriangle g) { return CLRConvert.GetDipOnlyColor(g.DipDeg); }
	
	public static void main(String[] args)
	{
		System.out.println("Testing GetStrikeOnlyColor(double)");
		for (int i = 0; i < 360*2; i++)
		{
			double strike = i;
			// go round and round until we are in range
			while (strike >= 360) strike = strike - 360.0;
			while (strike < 0) strike = strike + 360.0;
			float[] rgb = CLRConvert.GetStrikeOnlyColor(strike);
			System.out.println("Strike("+ strike +") ==> RGB[ " + (rgb[0]*255) + " , " + (rgb[1]*255) + " , " + (rgb[2]*255) + " ]");
		}
		System.out.println("Testing GetDipOnlyColor(double)");
		for (int i = 0; i < 90; i++)
		{
			float[] rgb = CLRConvert.GetDipOnlyColor(i);
			System.out.println("Dip("+ i +") ==> RGB[ " + (rgb[0]*255) + " , " + (rgb[1]*255) + " , " + (rgb[2]*255) + " ]");
		}
	}
}